﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;


public partial class View_IMG_IMG001_I : ViewMatrix
{
    string[] keyList = { "fldname", "fldvalue", "seq" };

    protected void Page_Load(object sender, EventArgs e)
    {
        Title = "匯損與避險科目維護";
        serviceName = "MISAPP.Classify.Service.Service_IMG001";
        lbl_result.Text = string.Empty;
        if (!IsPostBack)
        {
            FillCriteria("GetCriteriaData", "SetData");
        }
    }

    protected void btn_ExecuteClick(object sender, EventArgs e)
    {
        Button btn = sender as Button;
        if (btn.Text.Equals("新增"))
        {
            insert();
        }
        else
        {
            query();
        }
        
    }

    protected void insert()
    {
        MISAPP.Classify.Service.Service_IMG001 img = 
            new MISAPP.Classify.Service.Service_IMG001();
        List<string> items = CLB_項目.GetSelectList();
        bool result = img.Insert(items[1]
            ,ucAccNOS.GetAutoCompleteValue());
        lbl_result.Text = result.Equals(false) ? 
            "新增失敗" : "";
    }

    protected void query()
    {
        MISAPP.Classify.Service.Service_IMG001 img =
                new MISAPP.Classify.Service.Service_IMG001();
        List<string> items = CLB_項目.GetSelectList();
        DataTable dt = img.Query(items[1]
            , ucAccNOS.GetAutoCompleteValue());
        CLB_Summary.SetData(dt, keyList);
    }

    protected void CLB_Summary_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "detail")
        {
            del(CLB_Summary.SelectKeyValue);
        }
    }
   
    protected void del(Dictionary<string, string> p_key) 
    {
        MISAPP.Classify.Service.Service_IMG001 img = 
            new MISAPP.Classify.Service.Service_IMG001();
        img.Del(p_key["fldname"].ToString()
            , p_key["fldvalue"].ToString()
            , p_key["seq"].ToString());
        query();
    }
}
